package com.commerceerp.system.controller;

import com.commerceerp.system.service.LoginService;
import com.commerceerp.system.service.WishService;
import com.commerceerp.system.util.ApiResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * Created by Administrator on 2018/7/12 0012.
 */
@Api(description = "客服", value = "客服")
@RestController
@RequestMapping("sysNotice")
public class SysNoticeController {

    @Autowired
    private LoginService loginService;

    @Autowired
    private WishService wishService;

    @ApiOperation(value = "wish-客服信息同步")
    @RequestMapping("wishTicket")
    public ApiResult wishTicket(HttpServletRequest request){
        String token = request.getHeader("token");
        ApiResult to = loginService.checkToken(token);
        if(to.getCode() != 200){
            return to;
        }
        return wishService.wishTicket((String)to.getData());
    }

    @ApiOperation(value = "wish-客服信息回复")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "id", value = "客服消息id", required = true, dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "reply", value = "回复内容", required = true, dataType = "String"),
    })
    @RequestMapping("wishReply")
    public ApiResult wishReply(String id,String reply,HttpServletRequest request){
        String token = request.getHeader("token");
        ApiResult to = loginService.checkToken(token);
        if(to.getCode() != 200){
            return to;
        }
        return wishService.wishReply(id,reply);
    }

    @ApiOperation(value = "wish-客服信息关闭")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "id", value = "客服消息id", required = true, dataType = "String"),
    })
    @RequestMapping("wishClose")
    public ApiResult wishClose(String id,HttpServletRequest request){
        String token = request.getHeader("token");
        ApiResult to = loginService.checkToken(token);
        if(to.getCode() != 200){
            return to;
        }
        return wishService.wishClose(id);
    }

}
